package com.dps.metrics.support;

import java.util.concurrent.ConcurrentHashMap;

public class LocalLockSupport {
    private static final ConcurrentHashMap<String, Byte[]> LOCK_MAP = new ConcurrentHashMap(16);

    private LocalLockSupport() {
    }

    public static Object getLockObject(String key) {
        Byte[] bytesLock = (Byte[]) LOCK_MAP.get(key);
        if (bytesLock != null) {
            return bytesLock;
        } else {
            bytesLock = new Byte[0];
            Byte[] existsBytesLock = (Byte[]) LOCK_MAP.putIfAbsent(key, bytesLock);
            return existsBytesLock == null ? bytesLock : existsBytesLock;
        }
    }
}
